package com.shop.front.dao.user;

import com.shop.jpa.BaseDao;
import com.shop.domain.user.UserBankCard;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserBankCardDao extends BaseDao<UserBankCard, Long> {

    @Modifying(clearAutomatically = true)
    @Query("update UserBankCard set isDefault = 0 where isDefault = 1 and uid = ?1")
    public int updateNotDefault(Long userId);

    @Query("from UserBankCard where isDefault = 1 and uid = ?1 and cardType = ?2")
    public UserBankCard findDefault(Long userId,String cardType);

    @Query("from UserBankCard where uid = ?1 and cardType=?2 order by isDefault desc, id desc")
    public List<UserBankCard> findByUid(Long userId,String cardType);


}
